<%@ page contentType="text/html;charset=UTF-8"%>

<!--
	用于嵌入到业务Form表单并与业务表单数据同时保存提交，
	但要注意表单要设置为“enctype="multipart/form-data"”
-->

<script	language="javascript">
 	/**
 	 * 根据当前附件的个数改变添加附件按钮上的文字
 	 * @param num 附件个数
 	 */
 	function changeBtnCharacter(num){
 		var dyncAddBtn = document.getElementById('dyncAddBtn');
 		if(num >= 1){
			dyncAddBtn.value = '继续添加';
		}
		else{
			dyncAddBtn.value = '添加附件';
		}
 	}
 	
 	/**
	 * 动态添加上传文件域及功能按钮
	 */
	function dyncAddUploadFileField(){
		var basicRowNum = 2;
		var table = document.getElementById("attachmentTable");
		var rnum = table.rows.length;
			
	    var newTr = table.insertRow(rnum);
	    rnum = table.rows.length;
	    changeBtnCharacter(rnum - basicRowNum);
	    
	    newTr.id = "row" + rnum;
	    
	    var newTd0 = newTr.insertCell(0);
	    var newTd1 = newTr.insertCell(1);
	    newTd0.setAttribute("className","td_header_r");
	    newTd0.setAttribute("width","150");
	    newTd1.setAttribute("className","td_header_l");
		    
	    newTd0.innerText = "请选择要上传的附件：";
	    newTd1.innerHTML = "<input name=\"attachment\" type=\"file\" size=\"80\" style=\"height:95%\">&nbsp;<input type=\"button\" value=\" 删除 \" onClick=\"dynamicDeleteUploadBtn(" + rnum +");\">";
	}

	/**
	 * 动态删除上传文件域及功能按钮
	 */
	function dynamicDeleteUploadBtn(rowIndex){
		var basicRowNum = 2;
		var table = document.getElementById("attachmentTable");
		attachmentTable.deleteRow(document.getElementById("row" + rowIndex).rowIndex);
		
		var rnum = table.rows.length;
		changeBtnCharacter(rnum - basicRowNum);
	}
</script>
 	
<!----------- 动态添加附件 ---------------->
<table id="attachmentTable" width="98%" class="tb_custom">
	<tr>
		<td class="td_header_l" colspan="5">
			<table width="100%"><tr>
				<th width="20"><img src="${ctx}/resources/images/icons/16_16/attach.png"/></th>
				<th align="left">附件管理</th>
			</tr></table>
		</td>
	</tr>
	<tr>
		<td class="td_header_l" colspan="2">
			&nbsp;<input type="button" value="添加附件" id='dyncAddBtn' onclick="dyncAddUploadFileField()"/>
		</td>
	</tr>
</table>